home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dispms / dispmsg.bas next >
BASIC Source File  |  1995-10-23  |  5KB  |  143 lines

  1. ' This section is required for the Rufan Redi DisplayMessage processing !
  2.  
  3. Type POINTAPI
  4.   X As Integer
  5.   Y As Integer
  6. End Type
  7. Type RECT
  8.   X As Integer
  9.   Y As Integer
  10.   Width As Integer
  11.   Height As Integer
  12. End Type
  13.  
  14. Global lpPoint As POINTAPI
  15. Global lpRect As RECT
  16.  
  17. Declare Sub GetCursorPos Lib "User" (lpPoint As POINTAPI)
  18. Declare Sub GetClientRect Lib "User" (ByVal hWnd As Integer, lpRect As RECT)
  19.  
  20. 'End of Rufan Redi DisplayMessage section
  21.  
  22. Sub DisplayMessage (Formname As Form)
  23.   'This procedure is the Rufan Redi DisplayMessage control
  24.   
  25.   ' Pause the timer
  26.   Formname.MessageTimer.Enabled = False
  27.   ' Initialise variables
  28.   MessageFound% = False
  29.   MessageTemp% = 0
  30.   
  31.   ' Locate the pointer, and find the size of the client area of the current form
  32.   Call GetCursorPos(lpPoint)
  33.   Call GetClientRect(Formname.hWnd, lpRect)
  34.   ' Use that information to find the poisiotn on the form that the pointer is at
  35.   WindowX = (lpPoint.X * Screen.TwipsPerPixelX) - Formname.Left + ((lpRect.Width * Screen.TwipsPerPixelX) - Formname.Width)
  36.   WindowY = (lpPoint.Y * Screen.TwipsPerPixelY) - Formname.Top + ((lpRect.Height * Screen.TwipsPerPixelY) - Formname.Height)
  37.   
  38.   ' Loop to find a matching button
  39.   While MessageFound% = False And MessageTemp% < Formname.Count
  40.     
  41.     Select Case Formname.Controls(MessageTemp%).Tag
  42.       ' Ignore objects with certain (or empty) tags
  43.     Case "Timer", "Printer", "Line", "Status Bar", ""
  44.     Case Else
  45.         ' check to see if the pointer is over the object
  46.       If Formname.Controls(MessageTemp%).Left <= WindowX And Formname.Controls(MessageTemp%).Left + Formname.Controls(MessageTemp%).Width >= WindowX Then
  47.         If Formname.Controls(MessageTemp%).Top <= WindowY And Formname.Controls(MessageTemp%).Top + Formname.Controls(MessageTemp%).Height >= WindowY Then
  48.           Formname.Message.Caption = Formname.Controls(MessageTemp%).Tag
  49.           MessageFound% = True
  50.         End If
  51.       End If
  52.     End Select
  53.     
  54.     MessageTemp% = MessageTemp% + 1
  55.   
  56.   Wend
  57.   
  58.   ' If no object is current, reset the message to the forms tag
  59.   If MessageFound% = False Or Trim$(Formname.Message.Caption) = "" Then
  60.     Formname.Message.Caption = Formname.Tag
  61.   End If
  62.   
  63.   ' Restart the timer
  64.   Formname.MessageTimer.Enabled = True
  65.  
  66. End Sub
  67.  
  68. Sub ReadMe ()
  69. ' DisplayMessage (c) Rufan Redi Productions 1994
  70. ' Version 1.0 - 5 May 94
  71.  
  72. ' - A section of VB3.0 code which may be included in your
  73. ' program to provide a user-definable message box which
  74. ' shows a description of the form object that the pointer
  75. ' is resting over.
  76. ' It's very small, very simple and probably easy to
  77. ' improve on, but - you've got it, why not try using it !
  78.  
  79. ' In order to make it work you must do the following;
  80. ' 1 - Include this Module in your code
  81. ' 2 - Add a Timer - called MessageTimer - to each form you
  82. '     want to have this function on. By default this should
  83. '     be disabled, with an Interval of 250. If this slows
  84. '     your application down, increase the number
  85. ' 3 - Add a Label - called Message - to each form with one
  86. '     of these Timers on - set it's size and attributes to
  87. '     fit your application
  88. ' 4 - Set the MessageTimer_Timer event to
  89. '     Call DisplayMessage(xxxx) where xxxx is the name of
  90. '     the form
  91. ' 5 - Set the Form_Activate event to
  92. '     MessageTimer.Enabled = True
  93. '     and the Form_Deactive event to
  94. '     MessageTimer.Enabled = False
  95. ' 6 - Set the tag property for the form to the default
  96. '     message
  97. ' 7 - Set the tag properties for each object you want to
  98. '     display a message for. Do not set tags for Timer,
  99. '     Line, Common Dialog or Printer objects.
  100. ' 8 - Run your application, and fine tune the messages
  101.  
  102. ' Tag values can be updated in the code. The next time the
  103. ' Message is displayed for that object, the new tag will
  104. ' be reflected
  105.  
  106. ' You can manually update the message by setting
  107. ' DisplayMessage.Caption to the text you want. Remember
  108. ' that if the MessageTimer.Enabled = True, that the
  109. ' message will be updated after the specified interval
  110.  
  111. ' Apart from DISPMSG.BAS - Declarations, DisplayMessage
  112. ' and this ReadMe there are no other pre-requisites
  113.  
  114. ' If you decide to use this in an application, please do
  115. ' two things;
  116. ' a) Credit me in an appropriate place in your application
  117. ' b) and send me a suitable donation to help me contine
  118. '    the work !
  119.  
  120. ' If you have problems, please contact me, preferably via
  121. ' CompuServe or physical mail, and preferably with a
  122. ' zipped copy of the code you are having problems with
  123. ' - I respond better to those who have made, or promise to
  124. ' make donations !
  125.  
  126. ' Please feel free to distribute this source - if you
  127. ' improve it, please comment the changes, and always
  128. ' distribute a copy of the unaltered original. If you do
  129. ' improve on this, please also send me a copy !
  130.  
  131. ' I accept no responsibility or liability for anything you
  132. ' do with this code, or anything that happens as a result
  133. ' of using in in it's original, or any modified forms.
  134.  
  135. ' I am Jeremy E Cath
  136. ' Address: Stoke Cottage, Marsh Lane, Taplow, Maidenhead,
  137. '          Berkshire. United Kingdom. SL6 0DF
  138. ' Phone/Fax +44 628 789229
  139. ' CompuServe: 100315,521
  140. ' Internet: 100315.521@CompuServe.Com
  141. End Sub
  142.  
  143.